package com.alavente.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.alavente.objects.DemandeVente;
import com.alavente.service.DemandeVenteManager;

public class ListeDemandesVenteAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
				
		Integer numCategorie = null;
		Integer numSsCategorie = null;
		
		try {
			numCategorie = Integer.parseInt(request.getParameter("numCategorie"));
		}
		catch(NumberFormatException e) {}
		
		try {
			numSsCategorie = Integer.parseInt(request.getParameter("numSsCategorie"));
		}
		catch(NumberFormatException e) {}
		
		List<DemandeVente> listDemandes;	
		if (numCategorie != null) {
			listDemandes = new DemandeVenteManager().getDemandeVenteCategorie(numCategorie);
		}
		else if (numSsCategorie != null) {
			listDemandes = new DemandeVenteManager().getDemandeVenteSsCategorie(numSsCategorie);
		}
		else {
			listDemandes = new DemandeVenteManager().getAllDemandeVente();
		}
		
		request.setAttribute("demandes", listDemandes);
		
		return mapping.findForward("success");
	}
}	
	
